/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ua.org.pslava.codingtest.factory;

import ua.org.pslava.codingtest.model.Product;
import java.util.HashMap;

/**
 * Encapsulates a functionality of product factory. <br/>
 *
 * 
 * @author Vyacheslav Panasyuk.
 */
public class ProductFactory implements IProductFactory {

    private HashMap<String, Product> products;

    public ProductFactory() {
        products = new HashMap<String, Product>();
    }

    @Override
    public void addProduct(Product product) {
        if (product != null && product.getName()!=null && !product.getName().isEmpty()) {
            products.put(product.getName(), product);
        }
    }

    @Override
    public Product getProduct(String productName) {
        return products.get(productName);
    }

    @Override
    public Product deleteProduct(String productName) {
        if (productName != null && !productName.isEmpty()) {
            return products.remove(productName);
        } 
        return null;
    }
}
